package com.lighting.smssystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lighting.smssystem.constrants.UserRole;
import com.lighting.smssystem.mapper.TemplateMapper;
import com.lighting.smssystem.model.Template;
import com.lighting.smssystem.model.User;
import com.lighting.smssystem.service.ITemplateService;
import com.lighting.smssystem.utils.SnowflakeIdWorker;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TemplateService implements ITemplateService {

    @Resource
    private TemplateMapper templateMapper;

    @Override
    public List<Template> listTemplate() {
        return templateMapper.selectList((new QueryWrapper<Template>()));
    }

    @Override
    public int delTemplate(Long templateId) {
        return templateMapper.delete((new QueryWrapper<Template>()).eq("template_id", templateId));
    }

    @Override
    public Template queryById(Long id) {
        return templateMapper.selectById(id);
    }

    @Override
    public int updateTemplate(Template template) {
        return templateMapper.update(template, Wrappers.<Template>update().eq("template_id", template.getTemplateId()));
    }

    @Override
    public int addTemplate(Template template) {
        template.setTemplateId(SnowflakeIdWorker.next());
        return templateMapper.insert(template);
    }
}
